using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySQL_SysFrameMVC.Message;
using System.Reflection;
using System.Data;
using MySql.Data.MySqlClient;
using SysFrame.Message;
using SysFrame.BP;
using TaskAPP.Message;

namespace TaskApp.BP
{
    /// <summary>
    /// taskapp_mainlist方法
    /// </summary>
    public class MySQLtaskapp_mainlist: Itaskapp_mainlist
    {

        /// <summary>
        /// 得到taskapp_mainlist实体
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public List<Mstaskapp_mainlist> Gettaskapp_mainlistMsByQuery(MsQuery msq)
        {
            List<Mstaskapp_mainlist> listms=new List<Mstaskapp_mainlist>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select taskapp_mainlist.* ");
            sb.Append(" from taskapp_mainlist ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if(msq.strorder != null && msq.strorder != "")
            {
				sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                DataSet ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
               if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0)
                {
                	foreach(DataRow dr in ds.Tables[0].Rows)
                	{
                    	Mstaskapp_mainlist ms = new Mstaskapp_mainlist();
                    	int? TASKAPP_MAINLIST_AUTOID = null;
                    	ms.TASKAPP_MAINLIST_AUTOID =  (int)dr["TASKAPP_MAINLIST_AUTOID"];// AutoID
                    	char? TASKAPP_MAINLIST_ISDEL = null;
                    	ms.TASKAPP_MAINLIST_ISDEL =  dr["TASKAPP_MAINLIST_ISDEL"].ToString();// 是否删除
                    	
                    	ms.TASKAPP_MAINLIST_MAKETIME =  dr["TASKAPP_MAINLIST_MAKETIME"].ToString();// 新增时间
                    	
                    	ms.TASKAPP_MAINLIST_MAKEUSER =  dr["TASKAPP_MAINLIST_MAKEUSER"].ToString();// 新增人
                    	
                    	ms.TASKAPP_MAINLIST_PARENTID =  dr["TASKAPP_MAINLIST_PARENTID"].ToString();// 上级ID
                    	
                    	ms.TASKAPP_MAINLIST_MAKEFROM =  dr["TASKAPP_MAINLIST_MAKEFROM"].ToString();// 来源
                    	int? TASKAPP_MAINLIST_10 = null;
                    	ms.TASKAPP_MAINLIST_10 =  (int)dr["TASKAPP_MAINLIST_10"];// 单据ID
                    	int? TASKAPP_MAINLIST_20 = null;
                    	ms.TASKAPP_MAINLIST_20 =   (int)dr["TASKAPP_MAINLIST_20"];// 资产ID
                    	
                    	ms.TASKAPP_MAINLIST_30 =  dr["TASKAPP_MAINLIST_30"].ToString();// 状态分类码
                    	
                    	ms.TASKAPP_MAINLIST_40 =  dr["TASKAPP_MAINLIST_40"].ToString();// 备用1
                    	
                    	ms.TASKAPP_MAINLIST_50 =  dr["TASKAPP_MAINLIST_50"].ToString();// 备用2
                    	
                    	ms.TASKAPP_MAINLIST_60 =  dr["TASKAPP_MAINLIST_60"].ToString();// 
                    	
                    	ms.TASKAPP_MAINLIST_70 =  dr["TASKAPP_MAINLIST_70"].ToString();// 
                    	
                    	ms.TASKAPP_MAINLIST_80 =  dr["TASKAPP_MAINLIST_80"].ToString();// 
                    	
                    	ms.TASKAPP_MAINLIST_90 =  dr["TASKAPP_MAINLIST_90"].ToString();// 
                    	
                    	ms.TASKAPP_MAINLIST_100 =  dr["TASKAPP_MAINLIST_100"].ToString();// 
                    	listms.Add(ms);
                	}
                }
            }
            catch{}
            return listms;
        }

        /// <summary>
        ///  保存taskapp_mainlist信息
        /// </summary>
        /// <param name="ms">实体信息 通过TASKAPP_MAINLIST_AUTOID进行判断有TASKAPP_MAINLIST_AUTOID就是update</param>
        /// <returns>消息</returns>
        public MsReturned Savetaskapp_mainlist(Mstaskapp_mainlist ms)
        {
            MsReturned msr = new MsReturned();
            if(ms.TASKAPP_MAINLIST_AUTOID !=null && ms.TASKAPP_MAINLIST_AUTOID.ToString() !="" && ms.TASKAPP_MAINLIST_AUTOID.ToString() != "0")
            {
            	msr = Uptaskapp_mainlist(ms);
            }
            else
            {
            	msr = Addtaskapp_mainlist(ms);
            }
            return msr;
        }

        /// <summary>
        ///  新增taskapp_mainlist信息
        /// </summary>
        /// <param name="ms">实体信息 通过TASKAPP_MAINLIST_AUTOID进行判断有TASKAPP_MAINLIST_AUTOID就是update</param>
        /// <returns>消息</returns>
        public MsReturned Addtaskapp_mainlist(Mstaskapp_mainlist ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
            int newRateId = DataBase.GetMaxId("taskapp_mainlist", "TASKAPP_MAINLIST_AUTOID");
            sb.Append("insert into taskapp_mainlist (");
            sb.Append("TASKAPP_MAINLIST_AUTOID,TASKAPP_MAINLIST_ISDEL,TASKAPP_MAINLIST_MAKETIME,TASKAPP_MAINLIST_MAKEUSER,TASKAPP_MAINLIST_PARENTID,");
            sb.Append("TASKAPP_MAINLIST_MAKEFROM,TASKAPP_MAINLIST_10,TASKAPP_MAINLIST_20,TASKAPP_MAINLIST_30,TASKAPP_MAINLIST_40,");
            sb.Append("TASKAPP_MAINLIST_50,TASKAPP_MAINLIST_60,TASKAPP_MAINLIST_70,TASKAPP_MAINLIST_80,TASKAPP_MAINLIST_90,");
            sb.Append("TASKAPP_MAINLIST_100");
            sb.Append(")");
            sb.Append("values ( ");
            sb.Append(newRateId.ToString()).Append(",");
            sb.Append("'");
            sb.Append(ms.TASKAPP_MAINLIST_ISDEL).Append("','");//TASKAPP_MAINLIST_ISDEL 是否删除
            sb.Append(ms.TASKAPP_MAINLIST_MAKETIME).Append("','");//TASKAPP_MAINLIST_MAKETIME 新增时间
            sb.Append(ms.TASKAPP_MAINLIST_MAKEUSER).Append("','");//TASKAPP_MAINLIST_MAKEUSER 新增人
            sb.Append(ms.TASKAPP_MAINLIST_PARENTID).Append("','");//TASKAPP_MAINLIST_PARENTID 上级ID
            sb.Append(ms.TASKAPP_MAINLIST_MAKEFROM).Append("','");//TASKAPP_MAINLIST_MAKEFROM 来源
            sb.Append(ms.TASKAPP_MAINLIST_10).Append("','");//TASKAPP_MAINLIST_10 单据ID
            sb.Append(ms.TASKAPP_MAINLIST_20).Append("','");//TASKAPP_MAINLIST_20 资产ID
            sb.Append(ms.TASKAPP_MAINLIST_30).Append("','");//TASKAPP_MAINLIST_30 状态分类码
            sb.Append(ms.TASKAPP_MAINLIST_40).Append("','");//TASKAPP_MAINLIST_40 备用1
            sb.Append(ms.TASKAPP_MAINLIST_50).Append("','");//TASKAPP_MAINLIST_50 备用2
            sb.Append(ms.TASKAPP_MAINLIST_60).Append("','");//TASKAPP_MAINLIST_60 
            sb.Append(ms.TASKAPP_MAINLIST_70).Append("','");//TASKAPP_MAINLIST_70 
            sb.Append(ms.TASKAPP_MAINLIST_80).Append("','");//TASKAPP_MAINLIST_80 
            sb.Append(ms.TASKAPP_MAINLIST_90).Append("','");//TASKAPP_MAINLIST_90 
            sb.Append(ms.TASKAPP_MAINLIST_100).Append("')");//TASKAPP_MAINLIST_100 
            MySqlParameter[] parameters = null;
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString(),parameters);
                if (iexe > 0)
                {
                    msr.strMsId = newRateId.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        ///  更新taskapp_mainlist信息
        /// </summary>
        /// <param name="ms">实体信息 通过TASKAPP_MAINLIST_AUTOID进行判断有TASKAPP_MAINLIST_AUTOID就是update</param>
        /// <returns>消息</returns>
        public MsReturned Uptaskapp_mainlist(Mstaskapp_mainlist ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
           	sb.Append("update taskapp_mainlist set ");
           	sb.Append(" TASKAPP_MAINLIST_AUTOID='").Append(ms.TASKAPP_MAINLIST_AUTOID).Append("' ");// TASKAPP_MAINLIST_AUTOID AutoID
           	if (ms.TASKAPP_MAINLIST_ISDEL !=null && ms.TASKAPP_MAINLIST_ISDEL.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_ISDEL='").Append(ms.TASKAPP_MAINLIST_ISDEL).Append("' ");// TASKAPP_MAINLIST_ISDEL 是否删除
           	}
           	if (ms.TASKAPP_MAINLIST_MAKETIME !=null && ms.TASKAPP_MAINLIST_MAKETIME.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_MAKETIME='").Append(ms.TASKAPP_MAINLIST_MAKETIME).Append("' ");// TASKAPP_MAINLIST_MAKETIME 新增时间
           	}
           	if (ms.TASKAPP_MAINLIST_MAKEUSER !=null && ms.TASKAPP_MAINLIST_MAKEUSER.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_MAKEUSER='").Append(ms.TASKAPP_MAINLIST_MAKEUSER).Append("' ");// TASKAPP_MAINLIST_MAKEUSER 新增人
           	}
           	if (ms.TASKAPP_MAINLIST_PARENTID !=null && ms.TASKAPP_MAINLIST_PARENTID.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_PARENTID='").Append(ms.TASKAPP_MAINLIST_PARENTID).Append("' ");// TASKAPP_MAINLIST_PARENTID 上级ID
           	}
           	if (ms.TASKAPP_MAINLIST_MAKEFROM !=null && ms.TASKAPP_MAINLIST_MAKEFROM.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_MAKEFROM='").Append(ms.TASKAPP_MAINLIST_MAKEFROM).Append("' ");// TASKAPP_MAINLIST_MAKEFROM 来源
           	}
           	if (ms.TASKAPP_MAINLIST_10 !=null && ms.TASKAPP_MAINLIST_10.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_10='").Append(ms.TASKAPP_MAINLIST_10).Append("' ");// TASKAPP_MAINLIST_10 单据ID
           	}
           	if (ms.TASKAPP_MAINLIST_20 !=null && ms.TASKAPP_MAINLIST_20.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_20='").Append(ms.TASKAPP_MAINLIST_20).Append("' ");// TASKAPP_MAINLIST_20 资产ID
           	}
           	if (ms.TASKAPP_MAINLIST_30 !=null && ms.TASKAPP_MAINLIST_30.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_30='").Append(ms.TASKAPP_MAINLIST_30).Append("' ");// TASKAPP_MAINLIST_30 状态分类码
           	}
           	if (ms.TASKAPP_MAINLIST_40 !=null && ms.TASKAPP_MAINLIST_40.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_40='").Append(ms.TASKAPP_MAINLIST_40).Append("' ");// TASKAPP_MAINLIST_40 备用1
           	}
           	if (ms.TASKAPP_MAINLIST_50 !=null && ms.TASKAPP_MAINLIST_50.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_50='").Append(ms.TASKAPP_MAINLIST_50).Append("' ");// TASKAPP_MAINLIST_50 备用2
           	}
           	if (ms.TASKAPP_MAINLIST_60 !=null && ms.TASKAPP_MAINLIST_60.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_60='").Append(ms.TASKAPP_MAINLIST_60).Append("' ");// TASKAPP_MAINLIST_60 
           	}
           	if (ms.TASKAPP_MAINLIST_70 !=null && ms.TASKAPP_MAINLIST_70.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_70='").Append(ms.TASKAPP_MAINLIST_70).Append("' ");// TASKAPP_MAINLIST_70 
           	}
           	if (ms.TASKAPP_MAINLIST_80 !=null && ms.TASKAPP_MAINLIST_80.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_80='").Append(ms.TASKAPP_MAINLIST_80).Append("' ");// TASKAPP_MAINLIST_80 
           	}
           	if (ms.TASKAPP_MAINLIST_90 !=null && ms.TASKAPP_MAINLIST_90.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_90='").Append(ms.TASKAPP_MAINLIST_90).Append("' ");// TASKAPP_MAINLIST_90 
           	}
           	if (ms.TASKAPP_MAINLIST_100 !=null && ms.TASKAPP_MAINLIST_100.ToString() != ""){
           	    sb.Append(",").Append(" TASKAPP_MAINLIST_100='").Append(ms.TASKAPP_MAINLIST_100).Append("' ");// TASKAPP_MAINLIST_100 
           	}
           	sb.Append(" where TASKAPP_MAINLIST_AUTOID='").Append(ms.TASKAPP_MAINLIST_AUTOID).Append("'");// TASKAPP_MAINLIST_AUTOID AutoID
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString());
                if (iexe > 0)
                {
                    msr.strMsId = ms.TASKAPP_MAINLIST_AUTOID.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        /// 得到数据类型
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns>数据类型</returns>
        public MsReturned Gettaskapp_mainlistByQuery(MsQuery msq)
        {
        	DataSet ds = null;
        	MsReturned msr = new MsReturned();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select taskapp_mainlist.* ");
            sb.Append(" from taskapp_mainlist ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if(msq.strorder!=null && msq.strorder != "")
            {
				sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
            }
            catch{}
            msr.data = ds;
            return msr;
        }

        /// <summary>
        /// 删除taskapp_mainlist
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public MsReturned Deletetaskapp_mainlistByQuery(MsQuery msq)
        {
            StringBuilder sb = new StringBuilder();
            MsReturned msr = new MsReturned();
            sb.Append(" delete from taskapp_mainlist where TASKAPP_MAINLIST_AUTOID > 0 ").Append(msq.strquery);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(sb.ToString());
                if (iexe > 0)
                {
                    msr.strMsId = "1";
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            sb = null;
            return msr;
        }

    }
}
